//
//  CommonMessageViewCell.m
//  TeamInformatization
//
//  Created by bigger on 2019/4/1.
//  Copyright © 2019年 SPIC. All rights reserved.
//

#import "CommonMessageViewCell.h"

@interface CommonMessageViewCell ()

// 标题
@property (nonatomic, strong) SimpleLabel *cellTitleLabel;
// 日期
@property (nonatomic, strong) SimpleLabel *showDateLabel;
// 图片
@property (nonatomic, strong) UIImageView *showImageView;
// 展示数据标题
@property (nonatomic, strong) SimpleLabel *subTitle1;
@property (nonatomic, strong) SimpleLabel *subTitle2;
// 展示数据
@property (nonatomic, strong) SimpleLabel *showContent1;
@property (nonatomic, strong) SimpleLabel *showContent2;


@end

@implementation CommonMessageViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatCellView];
        
        self.backgroundColor = kCommonBGGaryColor;
        // 取消cell选中状态
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)creatCellView
{
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = [UIColor whiteColor];
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15 * kScaleWidth);
        make.right.mas_equalTo(-15 * kScaleWidth);
        make.top.mas_equalTo(5 * kScaleWidth);
        make.bottom.mas_equalTo(-5 * kScaleWidth);
    }];
    
    //
    self.cellTitleLabel = [SimpleLabel initWithText:@"" TextColor:kTitleTextColor TextFont:[UIFont fontWithName:@"PingFangSC-Medium" size:15] TextAlignment:NSTextAlignmentLeft];
    [bgView addSubview:_cellTitleLabel];
    [_cellTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10 * kScaleWidth);
        make.top.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(120, 45 * kScaleWidth));
    }];
    
    //
    self.showDateLabel = [SimpleLabel initWithText:@"" TextColor:kTitleTextColor TextFont:[UIFont fontWithName:@"PingFangSC-Regular" size:13] TextAlignment:NSTextAlignmentRight];
    [bgView addSubview:_showDateLabel];
    [_showDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10 * kScaleWidth);
        make.centerY.mas_equalTo(self.cellTitleLabel);
    }];
    
    // 分割线
    UILabel *lineLabel = [[UILabel alloc] init];
    lineLabel.backgroundColor = kCuttingLineColor;
    [bgView addSubview:lineLabel];
    [lineLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(45 * kScaleWidth);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    
    //
    self.showImageView = [[UIImageView alloc] init];
    [bgView addSubview:_showImageView];
    [_showImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10 * kScaleWidth);
        make.bottom.mas_equalTo(-15 * kScaleWidth);
        make.size.mas_equalTo(CGSizeMake(120 * kScaleWidth, 80 * kScaleWidth));
    }];
    
    // 展示数据
    self.subTitle1 = [SimpleLabel initWithText:@"" TextColor:kSetRGBColor(102, 102, 102, 1) TextFont:[UIFont fontWithName:@"PingFangSC-Regular" size:12] TextAlignment:NSTextAlignmentLeft];
    [bgView addSubview:_subTitle1];
    [_subTitle1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.showImageView.mas_right).offset(10 * kScaleWidth);
        make.right.mas_equalTo(-10 * kScaleWidth);
        make.top.mas_equalTo(self.showImageView);
    }];

    self.showContent1 = [SimpleLabel initWithText:@"" TextColor:kTitleTextColor TextFont:[UIFont fontWithName:@"PingFangSC-Regular" size:13] TextAlignment:NSTextAlignmentLeft];
    [bgView addSubview:_showContent1];
    [_showContent1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.subTitle1);
        make.right.mas_equalTo(self.subTitle1);
        make.top.mas_equalTo(self.subTitle1.mas_bottom);
    }];
    
    
    self.showContent2 = [SimpleLabel initWithText:@"" TextColor:kTitleTextColor TextFont:[UIFont fontWithName:@"PingFangSC-Regular" size:13] TextAlignment:NSTextAlignmentLeft];
    [bgView addSubview:_showContent2];
    [_showContent2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.subTitle1);
        make.right.mas_equalTo(self.subTitle1);
        make.bottom.mas_equalTo(self.showImageView.mas_bottom);
    }];

    self.subTitle2 = [SimpleLabel initWithText:@"" TextColor:kSetRGBColor(102, 102, 102, 1) TextFont:[UIFont fontWithName:@"PingFangSC-Regular" size:12] TextAlignment:NSTextAlignmentLeft];
    [bgView addSubview:_subTitle2];
    [_subTitle2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.subTitle1);
        make.right.mas_equalTo(self.subTitle1);
        make.bottom.mas_equalTo(self.showContent2.mas_top);
    }];

}
- (void)setShowCellWithCommonMessage:(CommonMessage *)commonMessage
{
    _cellTitleLabel.text = commonMessage.title;
    _showDateLabel.text = commonMessage.date;
    [_showImageView sd_setImageWithURL:[NSURL URLWithString:commonMessage.imageStr]];
    _subTitle1.text = commonMessage.subTitle1;
    _subTitle2.text = commonMessage.subTitle2;
    _showContent1.text = commonMessage.contentStr1;
    _showContent2.text = commonMessage.contentStr2;

}


//
- (void)setShowCellWithMeetingData:(MeetingData *)meetData MeetType:(int)meetType
{
    double time = [[NSString stringWithFormat:@"%@", meetData.createTime] doubleValue] / 1000.;
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *showDate = [NSDate dateWithTimeIntervalSince1970:time];
    
    NSString *destDateString = [dateFormatter stringFromDate:showDate];
    if (meetType == 1) {
        _cellTitleLabel.text = @"班前会";
    } else if (meetType == 2){
        _cellTitleLabel.text = @"班后会";
    } else {
        _cellTitleLabel.text = @"工前会";
    }
    _showDateLabel.text = destDateString;
//    [_showImageView sd_setImageWithURL:[NSURL URLWithString:commonMessage.imageStr]];
    _subTitle1.text = @"所在班组";
    _subTitle2.text = @"参加人员";
//    _showContent1.text = @"参加人员";
//    _showContent2.text = commonMessage.contentStr2;
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
